# coding=utf-8
"""
Copyright (c) Huawei Technologies Co., Ltd. 2020-2028. All rights reserved.
Description:
FileName：search.py
Author: h00568282/huangbin
Create Date: 2025/9/20 17:09
Notes:

在mcp center中查找类似的mcp server
"""
import os
import shutil
from pathlib import Path

from sys_intd.constant import PROJECT_MCP_CENTER_PATH
from sys_intd.exceptions import MCPServerUninstallError
from sys_intd.manager import McpServerManager



def uninstall(server_name: str):
    mcp_server_manager = McpServerManager()

    output_lines = []
    if mcp_server_manager.remove_server(server_name):
        output_lines.append(f"[bold green]mcp server has been removed![/]")
    else:
        raise MCPServerUninstallError(f"Server '{server_name}' not found")

    server_src = os.path.join(PROJECT_MCP_CENTER_PATH, "servers", server_name)
    venv_root = Path(f"{server_src}/.venv")
    if venv_root.exists():
        shutil.rmtree(venv_root)
        output_lines.append(f"[bold green]mcp server's venv has been removed![/]")

    return output_lines
